package com.wkk.nursinghome.dao;

import com.wkk.nursinghome.domain.Employee;
import org.apache.ibatis.jdbc.SQL;

public class EmployeeSQLProvider {
    public String updateEmployee(Employee employee){
        return new SQL(){
            {
                UPDATE("employee");
                if(null!=employee.getName()){
                    SET("name=#{name}");
                }
                if(null!=employee.getSex()){
                    SET("sex=#{sex}");
                }
                if(null!=employee.getAge()){
                    SET("age=#{age}");
                }
                if(null!=employee.getEmnumber()){
                    SET("emnumber=#{emnumber}");
                }
                if(null!=employee.getType()){
                    SET("type=#{type}");
                }
                if(null!=employee.getEntrytime()){
                    SET("entrytime=#{entrytime}");
                }
                if(null!=employee.getOperator()){
                    SET("operator=#{operator}");
                }
                if(null!=employee.getOptime()){
                    SET("optime=#{optime}");
                }
                if(null!=employee.getPosition()){
                    SET("position=#{position}");
                }
                if(null!=employee.getJobtitle()){
                    SET("jobtitle=#{jobtitle}");
                }
                if(null!=employee.getStatus()){
                    SET("status=#{status}");
                }
                if(null!=employee.getIntroduction()){
                    SET("introduction=#{introduction}");
                }
                if(null!=employee.getRemarks()){
                    SET("remarks=#{remarks}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }
    //根据条件查询信息
    public String selectEmployeeByCondition(Employee employee){
        return new SQL(){
            {
                SELECT("*");
                FROM("employee");
                //使用动态SQL拼接查询条件
                if(null!=employee.getName()){
                    WHERE("name like concat('%',#{name},'%')");
                }
                if(null!=employee.getType()){
                    WHERE("type=#{type}");
                }

            }
        }.toString();
    }
}
